//
//  Logger.h
//  symbrion
//
//  Created by Berend Weel on 5/4/13.
//  Copyright (c) 2013 Berend Weel. All rights reserved.
//

#ifndef symbrion_Logger_h
#define symbrion_Logger_h

#define __MY_FILE__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#define logMessage(...) Logger::createMessage(__MY_FILE__, __FUNCTION__, __LINE__, __VA_ARGS__,NULL)

#define LOG4CPP_FIX_ERROR_COLLISION 1 //Using this to fix the compile error
#include <log4cpp/Category.hh>
#include <log4cpp/PropertyConfigurator.hh>

class Logger {
public:
    static log4cpp::Category &getRootInstance(){
        checkConfigured();
        return log4cpp::Category::getRoot();
    }
    
    static log4cpp::Category &getFitnessLogger(){
        checkConfigured();
        return log4cpp::Category::getInstance("fitness");
    }
    
    static std::string createMessage(std::string file, std::string function, int line, ...){
        va_list arguments;
        
        std::stringstream logstring;
        logstring << file << " " << function << ":" << line << " - ";
        
        va_start ( arguments, line );           // Initializing arguments to store all values after num
        for ( ; ; ) {
            char *s = va_arg(arguments, char* );
            if(!s)
                break;
            logstring << s;
        }
        va_end ( arguments );                  // Cleans up the list
        
        return logstring.str();
    }
    
    static void checkConfigured(){
        if(!configured)
            log4cpp::PropertyConfigurator::configure("demologger.config");
    }
    
private:
    Logger(){
    }
    
    static bool configured;
};

#endif
